package cn.reinforce.util.juhe.function;

import cn.reinforce.util.http.HttpClientUtil;
import cn.reinforce.util.juhe.common.JuheConsts;
import cn.reinforce.util.juhe.exception.JuheException;
import cn.reinforce.util.juhe.model.IP;
import cn.reinforce.util.juhe.model.Joke;
import cn.reinforce.util.juhe.model.JokeData;
import cn.reinforce.util.juhe.model.JuheResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 幻幻Fate
 * @create 2019/12/23
 * @since
 */
public class JokeUtil {

    public static JuheResponse random(String key) {
        Gson gson = new GsonBuilder().create();

        String result = HttpClientUtil.get("http://v.juhe.cn/joke/randJoke.php?key=" + key).getResult();
        JuheResponse response = gson.fromJson(result, JuheResponse.class);
        List<Joke> jokes = gson.fromJson(gson.toJson(response.getResult()), new TypeToken<List<Joke>>(){}.getType());
        response.setJokes(jokes);

        return response;
    }
}
